package com.example.futureai.controller.chat;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.futureai.constants.Result;
import com.example.futureai.dto.DocSgtDto;
import com.example.futureai.dto.SendMsgDto;
import com.example.futureai.mapper.chat.ChatDocumentRecordMapper;
import com.example.futureai.mapper.chat.DocSgtMapper;
import com.example.futureai.po.ChatDocumentRecord;
import com.example.futureai.po.ChatSessionRecord;
import com.example.futureai.po.DocSgtPo;
import com.example.futureai.service.ZskService;
import com.example.futureai.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ZskController
 * @Description:
 * @Author: YourName
 * @Date: 2025/3/5
 */

@RestController
@Slf4j
@RequestMapping("/zsk")
public class ZskController {
    @Autowired
    private ChatDocumentRecordMapper chatDocumentRecordMapper;
    @Autowired
    private DocSgtMapper docSgtMapper;
    @Autowired
    private ZskService zskService;


    @GetMapping("/getZskList")
    public Result getZskList() {
        QueryWrapper<ChatDocumentRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.groupBy("doc_id");
        ChatDocumentRecord query = new ChatDocumentRecord();
        query.setUsername(TokenUtil.getCurrentUserId());
        queryWrapper.setEntity(query);
        List<ChatDocumentRecord> chatDocumentRecords = chatDocumentRecordMapper.selectList(queryWrapper);
        return Result.OK(chatDocumentRecords);
    }

    @GetMapping("/getSgtList")
    public Result getSgtList(String docId) {
        Result res = new Result();
        if(StrUtil.isBlank(docId)){
            return  res.ok(new ArrayList<>());
        }
        Map <String, Object> params = new HashMap<>();
        params.put("doc_id", docId);
        List<DocSgtPo> sgtPoList = docSgtMapper.selectByMap(params);
        return res.ok(sgtPoList);
    }
}
